package config;


import mapper.MappedStatement;
import mapper.MapperRegistry;

import java.util.HashMap;
import java.util.Map;

public class Configuration {
    //用于存储所有方法 建为方法名加类名和方法对应的sql语句
    /**
     * Key: 方法名称
     * Value: Sql语句及其类型
     */
    protected final Map<String, MappedStatement> mappedStatements;
    /**
     * 主要用于存储ORM接口及其动态代理工厂
     */
    protected final MapperRegistry mapperRegistry;

    public Configuration() {
        this.mappedStatements = new HashMap<String, MappedStatement>();
        this.mapperRegistry = new MapperRegistry(this);
    }


    public Map<String, MappedStatement> getMappedStatements() {
        return mappedStatements;
    }

    public MappedStatement getMappedStatement(String name) {
        return this.mappedStatements.get(name);
    }

    public <T> T getMapper(Class<T> type) {
        return mapperRegistry.getMapper(type);
    }

    public MapperRegistry getMapperRegistry() {
        return mapperRegistry;
    }

    @Override
    public String toString() {
        return "Configuration";
    }
}